<template>
  <div>
    <nav>
      <ul class="nav-tabs">
      
        <li >
          <router-link to="/popular" exact>热门</router-link>
        </li>
        <li >
          <router-link to="/outfit" exact>穿搭</router-link>
        </li>
        <li>
          <router-link to="/beauty" exact>美妆</router-link>
        </li>
      </ul>
</nav>
    <router-view></router-view>
    <div v-if="liveData && liveData.lives">
      <div v-for="item in liveData.lives" :key="item.roomId" class="live-card">
        <!-- 直播间头部信息 -->
        <div class="header">
          <img class="avatar" :src="item.avatar" alt="Avatar">
          <div class="host-info">
            <h3>{{ item.userName }}</h3>
            <div class="live-info">
              <div class="dot">
            </div> <div class="status">直播中
            </div>
             <div class="watch-num"><img src="https://s10.mogucdn.com/mlcdn/c45406/180927_1g764cjegegb6ecbh1jaa89gbh13l_30x30.png" alt="Fire Icon">
              <span>4.8W</span></div>
            </div>
            <span class="live-title">{{ item.intro }}</span>
            <!-- <p>直播中 {{ item.visitorCount }} 人观看</p> -->
          </div>
        </div>

        <!-- 直播内容 -->
        <div class="live-content"   >
            <img :src="item.bgImg" alt="Live Image" class="live-image">    
          <div class="live-text">
            <p>{{ item.liveText }}</p>
          </div>
        </div>

        <!-- 商品列表 -->
        <div class="products" v-if="item.shopCarts && item.shopCarts.goods.length">
          <div class="product-list">
            <div v-for="product in item.shopCarts.goods" :key="product.itemId" class="product-item">
         
              <!-- <p>{{ product.title }}</p>
              <p>{{ product.discountPrice }}</p> -->
              <p>{{ product.price }}</p>
              <img :src="product.cover" alt="Product Image">
            </div>
          </div>
        </div>

        <!-- 评论区 -->
        <div class="comments" v-if="item.comments && item.comments.length">
          <div class="comment-list">
            <div v-for="comment in item.comments" :key="comment.id" class="comment-item">
                   <img :src="comment.avatar"  alt=""> 
                  <span class="horizontal-text">{{comment.content}}</span>          
            </div>
          </div>
        </div>
      </div>
    </div>
    <p v-else>Loading...</p>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue';
import axios from 'axios';
const activeTab = ref('/'); // 默认选中热门
// 定义 setActiveTab 方法来更新 activeTab 的值
function setActiveTab(tabName) {
  activeTab.value = tabName;
}
const loading = ref(true);
const liveData = ref(null);
const tabId = 60; // 使用固定的 tabId

// Fetch live data based on the provided tabId
const fetchLiveData = async () => {
  try {
    const response = await axios.get(`https://apis.netstart.cn/mogujie/live/tabList?tabId=${tabId}`);
    liveData.value = response.data.data;
  } catch (error) {
    console.error('Failed to fetch live data:', error);
  } finally {
    loading.value = false;
  }
};

onMounted(() => {
  fetchLiveData();
});
</script>

<style scoped>
.live-card {
  position: relative;
  width: 350rem; /* 设置宽度为 350rem */
  background-color: #fff;
  height: auto; /* 高度自适应内容 */
  border-radius: 8px;
  overflow: hidden; /* 确保内容不会溢出 */
}

.header {
  display: flex;
  align-items: center;
  margin-bottom: 10px;
}

.header .live-title {
  position: absolute;
  top: 130px;
  left: 6px;
  color: #fff;
  padding: 5px;
  border-radius: 5px;
  z-index: 1;
}

.avatar {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  margin-right: 10px;
  position: absolute;
  top: 0;
  left: 10px;
  z-index: 1;
}

.host-info h3 {
  margin: 0;
  font-size: 16px;
  font-weight: bold;
  margin-left: 70px;
}

.host-info p {
  margin: 0;
  font-size: 14px;
  color: #666;
 
}

.live-content {
  position: relative; /* 确保.live-content是相对定位 */
  margin-bottom: 10px;
}

.live-image {
  width: 100%;
  height: 200rem;
  object-fit: cover;
  border-radius: 8px;
  z-index: 1; /* 设置.live-image的z-index */
  
}
.live-text {
  position: absolute;
  bottom: 10px;
  left: 10px;
  background-color: rgba(0, 0, 0, 0.5);
  color: #fff;
  padding: 5px;
  border-radius: 5px;
}

.products {
  position: absolute; /* 设置.products为绝对定位 */
  top: 185px; /* 根据需要调整 */
  left: 10px; /* 根据需要调整 */
  right: 0; /* 根据需要调整 */
  bottom: 0; /* 根据需要调整 */
  display: flex;
  flex-wrap: wrap;
  margin-top: 0; /* 移除外边距，因为它现在是堆叠在.live-image上 */
  z-index: 2; /* 设置.products的z-index，确保它在.live-image之上 */
}
 


.product-list {
  display: flex;
  flex-wrap: wrap;
  position: absolute;
  top: -25px;
  left: 0;
}
.product-list p{
  position: absolute;
  top: 40px;
  left: 4px;
  color: #fff;
  font-weight: 500;
 
}

.product-item {
  width: calc(33.333% - 10px);
  margin-bottom: 10px;
  margin-right: 10px;
  position: relative; /* 确保.product-item是相对定位 */
}
.product-item img {
  width: 60rem;
  height: 60rem;
  border-radius: 8px;
  z-index: 3; /* 设置.product-item img的z-index，确保它在.live-image之上 */
}

.product-item p {
  margin: 5px 0;
  font-size: 14px;
 
}

.comments {
  margin-top: 15px;
  position: absolute;
  top: 160px;
  left: 250px;
  width: 150px;
  height: 100px;
  display: flex;
}

.comment-list {
  position: absolute;
  top: -20px;
  left: -35px;
   width: 50px;
   height: 50px;
}
.comment-list img{
  width: 20px;
  height: 20px;
  border-radius: 50%;

}
.comment-item {
  width: calc(50% - 10px);
  margin-bottom: 10px;
  margin-right: 10px;
  width: 40px;
  height: 40px;
  
}

.comment-item p {
  margin: 0;
  font-size: 14px;
  color: #666;
  z-index: 1;
  width: 15rem;
}
.live-info {
  display: flex;
  align-items: center;
  background-color: rgba(0, 0, 0, 0.26);
  border-radius: 3px;
  padding: 5px 10px;
  color: #fff;
  font-size: 14px;
  position: absolute;
  top: 100px;
  left: 10px;
  z-index: 1;
}

.dot {
  width: 10px;
  height: 10px;
  background-color: #f5342f;
  border-radius: 50%;
  margin-right: 5px;
  animation: dot-flicker 2s infinite;
}

@keyframes dot-flicker {
  0% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
  100% {
    opacity: 1;
  }
}
.status {
  margin-right: 10px;
  padding-right: 10px;
  border-right: 1px solid rgba(255, 255, 255, 0.5);
}

.watch-num {
  display: flex;
  align-items: center;
}

.watch-num img {
  width: 14px;
  height: 14px;
  margin-right: 5px;
}

.watch-num span {
  font-size: 14px;
}
.nav-tabs .router-link-exact-active {
  border-bottom: 2px solid #e91e63; /* 选中项下划线 */
  color: #e91e63; /* 选中项字体颜色 */
}

.nav-tabs {
  list-style: none;
  padding: 0;
  display: flex;
  justify-content: space-around; /* 使标签均匀分布 */
  background-color: #f8f8f8; /* 背景颜色 */
}

.nav-tabs li {
  display: inline-block; /* 使列表项水平排列 */
  margin: 0; /* 移除默认的外边距 */
}

.nav-tabs a {
  display: block;
  padding: 10px 20px; /* 内边距 */
  text-decoration: none; /* 移除下划线 */
  color: #333; /* 字体颜色 */
}
.horizontal-text{
  display: flex;
  position: absolute;
  top: 0;
  left: 20px;
  width: 120px;
  font-size: 10px;
    -webkit-flex: 1;
    -moz-box-flex: 1;
    -ms-flex: 1;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: #fff;
    font-weight: 500;
    font-size: 11rem;
    text-shadow: 0 1px 2px rgba(0, 0, 0, .35);
}
</style>